﻿using ConfExpert.Forms.Base;
using Extensions;
using System;

namespace ConfExpert.Forms.Sistem
{
    public partial class Kisaltmalar : XForm
    {
        string TABLE_NAME;
        public Kisaltmalar(string TABLE_NAME)
        {
            InitializeComponent();
            this.TABLE_NAME = TABLE_NAME;
            this.Text += "- " + TABLE_NAME;
        }

        private void Kisaltmalar_Load(object sender, EventArgs e)
        {
            
            btnKaydet.ItemClick += btnKaydet_ItemClick;

            gridView1.Init("GetKisaltmalar", TABLE_NAME);
            gridView1.AddSummary();
            gridView1.BestFitColumns();

            if (TABLE_NAME == "Brand")
                gridView1.MakeEditable("CustomerId", "BrandId");
            else
                gridView1.MakeEditable("VendorId");

            //gridView1.ShowingEditor += gridView1_ShowingEditor;
        }

        //void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        //{
        //    e.Cancel = gridView1.FocusedColumn.FieldName == "CustomerId";
        //}

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEdit();
            switch (TABLE_NAME)
            {
                case "Vendor": gridView1.Update("VendorId, Abbr, OriginId, StokTipiId, SorumluId", TABLE_NAME); break;
                case "Brand": gridView1.Update("BrandId, Abbr, CustomerId", TABLE_NAME); break;
            }
        }
    }
}
